#include <iostream>
#include <string>
#include <set>
using namespace std;

namespace Test
{
    class Person
    {
    public:
        Person(string name, int age):m_Name(name), m_Age(age){}
        string m_Name;
        int m_Age;
    };

    class comparePerson
    {
    public:
        bool operator()(const Person &p1, const Person &p2) const
        {
            // 按照年龄
            return p1.m_Age > p2.m_Age;
        }
    };

    void printSet(const set<Person, comparePerson> &S)
    {
        for (auto &it : S) {
            cout << "姓名：" << it.m_Name << ", 年龄：" << it.m_Age << endl;
        }
    }

    // set 容器排序，存放自定义数据消息类型
    void test01()
    {
        // 自定义数据类型都会指定排序规则
        set<Person, comparePerson> s;
        Person p1("刘备", 24);
        Person p2("关羽", 28);
        Person p3("张飞", 25);
        Person p4("赵云", 21);

        s.insert(p1);
        s.insert(p2);
        s.insert(p3);
        s.insert(p4);

        printSet(s);
    }
}


int main()
{
    Test::test01();
}